﻿using UnityEngine;
using System.Collections;

[AddComponentMenu("theGift/Common/Alive")]
public class alive : MonoBehaviour
{
	public float life = 100;
	public float lifeMax = 100;

	public bool  lifeTriggerGainActive = false;
	public float lifeTriggerGainAmount = 0.5f;
	public float lifeTriggerGainMile = 0.1f;
	private float lifeTriggerGainNext = 0.0f;


	public void doLifeLoss(float amount)
	{
		life -= amount;
	}

	public void doLifeGain(float amount)
	{
		life += amount;
	}

	public void doTriggeredGainLife(float amount = 0.0f)
	{

	}

	public void doDie()
	{
		life = 0;
	}

	void FixedUpdate()
	{
		//Faire remonter la vie si le trigger est actif
		//Le délai d'exécution est paramétré dans lifeTriggerGain
		//Le gain de vie est paramétré dans lifeTriggerGainAmount
		//Le max de vie est paramétré dans lifeMax
		if (life < lifeMax)
		{
			if (lifeTriggerGainActive && Time.time > lifeTriggerGainNext)
			{
				lifeTriggerGainNext = Time.time + lifeTriggerGainMile;
				doLifeGain(lifeTriggerGainAmount);
			}
		} else life = lifeMax;
	}
}
